package com.shadowtorcher.TableRolePlayingSystem.controller.WebSocket;

import com.shadowtorcher.TableRolePlayingSystem.bean.Map;

import java.util.Collection;
import java.util.HashMap;

public class WebSocketRoom {
    private Map gameMap;
    private String dmName;
    private HashMap<String, WebSocketUser> users = new HashMap<>();

    public WebSocketRoom(Map gameMap) {
        assert gameMap != null;
        this.gameMap = gameMap;
        this.dmName = gameMap.getOwnerName();
    }

    public void updateMapData(String s) {
        this.gameMap.setRoomDate(s);
        SaveProcessor.updateMapData(this.gameMap);
    }

    public WebSocketUser getUser(String username) {
        return this.users.get(username);
    }

    public void addUser(WebSocketUser webSocketUser) {
        this.users.put(webSocketUser.getUserName(), webSocketUser);
    }

    public Collection<WebSocketUser> getAllUser() {
        return users.values();
    }

    public void removeUser(WebSocketUser user) {
        users.remove(user.getUserName());
    }

    public String getDmName() {
        return dmName;
    }

    public Map getGameMap() {
        return gameMap;
    }
}
